import Http from "../http";

export function devicePaginationApi(params:any) {
    return Http.get('device/list', params)
}

export async function addDeviceApi(data:any) {
    return await Http.post('device/add', data)
}

export async function editdeviceApi(deviceId:number, data:any) {
    return await Http.put('device/edit/' + deviceId, data)
}

export async function getdeviceEditDataApi(deviceId:number) {
    const { data } = await Http.get('device/edit/' + deviceId)
    return data
}

export async function toggledeviceStatusApi(deviceId:number, currentStatus:number) {
    let url = ''
    switch(currentStatus) {
        case 0 : url = 'enable'
            break
        case 1 : url = 'forbidden'
            break
    }

    const { success } = await Http.put('device/' + url + '/' + deviceId)

    return success
}


export async function querydeviceNameApi(name:string) {
    return Http.get('device/list/' + name)
}


export async function allotMerchantApi(merchantId:number, deviceIds:number[]) {
    return Http.post<boolean>('device/allotMerchant', {merchantId, deviceIds})
}

export async function setStrategyApi(strategyId:number, deviceIds:number[]) {
    return Http.post<boolean>('device/setStrategy', {strategyId, deviceIds})
}